<template>
  <table-block>
    <template-query
      slot="query"
      :configs="queryListFields"
      inline-item
      @query="handleSearch"
    >
    </template-query>
    <template-table
      :datas="datas"
      is-order-number
      :loading="isLoading"
      :configs="orderListFields"
      need-mark-prop="status"
      :need-mark-prop-val="-1"
      @refresh="fetchData"
    >
      <el-table-column fixed="right" label="操作" width="135">
        <template slot-scope="{ row }">
          <popconfirm
            v-if="row.status === 2"
            title="退款"
            text="是否退款?"
            @confirm="refund(row)"
          />
        </template>
      </el-table-column>
    </template-table>
    <el-pagination
      slot="pagination"
      :current-page="page"
      :page-size="limit"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @current-change="handlePageChange"
      @size-change="handleLimitChange"
    />
  </table-block>
</template>

<script>
const uniPayCo = uniCloud.importObject("uni-pay-co");
import { getOrderList } from 'dependencies/api/order'
import { orderListFields, queryListFields, columns } from './config'
import TablePageMixins from 'modules/mixins/table-page'
export default {
  name: 'SdkActivityList',
  mixins: [TablePageMixins],
  data() {
    return {
      orderListFields,
      queryListFields,
      queryParam: {}
    }
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    getDatas() {
      return getOrderList({
        formData: this.queryParam,
        pageIndex: this.page,
        pageSize: this.limit,
        columns: columns
      })
    },
    async refund(row) {
      try {
        await uniPayCo.refund({
          out_trade_no: row.transaction_id, // 插件支付单号
        });
        vk.callFunction({
        	url: 'client/order/kh/refund',
        	title: '请求中...',
        	data: {
        		_id: row._id
        	},
        	success: (data) => {
        		this.$message.success('操作成功!')
        		this.fetchData()
        	}
        });
      }catch(err){
        //
      }
    },
    handleSearch(params) {
      this.queryParam = { ...params }
      this.page = 1
      this.fetchData()
    }
  }
}
</script>
